.macro intr_stub nr
.global intr_stub_\nr
intr_stub_\nr:
    pushl $0
    pushl $\nr
    jmp intr_common_handler
.endm
 
.macro intr_stub_tim nr
.global intr_stub_\nr
intr_stub_\nr:
    jmp intr_common_handler_tim
.endm

.macro intr_stub_error_code nr
.global intr_stub_\nr
intr_stub_\nr:
    pushl $\nr
    jmp intr_common_handler
.endm
 
// Exceptions
intr_stub 0
intr_stub 1
intr_stub 2
intr_stub 3
intr_stub 4
intr_stub 5
intr_stub 6
intr_stub 7
intr_stub_error_code 8
intr_stub 9
intr_stub_error_code 10
intr_stub_error_code 11
intr_stub_error_code 12
intr_stub_error_code 13
intr_stub_error_code 14
intr_stub 15
intr_stub 16
intr_stub_error_code 17
intr_stub 18
 
// IRQs
//intr_stub_tim 32
intr_stub 33
intr_stub 34
intr_stub 35
intr_stub 36
intr_stub 37
intr_stub 38
intr_stub 39
intr_stub 40
intr_stub 41
intr_stub 42
intr_stub 43
intr_stub 44
intr_stub 45
intr_stub 46
intr_stub 47
 
// Syscall
intr_stub 48

.extern scheduler
.global mulTask
mulTask:
   push %eax
   push %ecx
   push %edx
   push %ebx
   push %ebp
   push %esi
   push %edi

   push %ds
   push %es
   push %fs
   push %gs

   mov $16, %ax
   mov %ax, %ds
   mov %ax, %es
   mov %ax, %fs
   mov %ax, %gs

   push %esp
   call scheduler
   mov %eax, %esp

   pop %gs
   pop %fs
   pop %es
   pop %ds
       
   pop %edi
   pop %esi
   pop %ebp
   pop %ebx
   pop %edx
   pop %ecx
   pop %eax

   iret

.extern handleInterrupt
.extern changePageDir
intr_common_handler:
    // CPU-Zustand sichern
    push %ebp
    push %edi
    push %esi
    push %edx
    push %ecx
    push %ebx
    push %eax
 
    // Handler aufrufen
    push %esp
    call handleInterrupt
    add $4, %esp
 
    // CPU-Zustand wiederherstellen
    pop %eax
    pop %ebx
    pop %ecx
    pop %edx
    pop %esi
    pop %edi
    pop %ebp
 
    // Fehlercode und Interruptnummer vom Stack nehmen
    add $8, %esp
 
    // Ruecksprung zum unterbrochenen Code
    iret
